<?php
/**
 * @todo Дописати проверки конфіга і якщо не прописані дані - другий кеш заюзати
 * Enter description here ...
 * @author megadevel
 *
 */
class Lib_Application_Resource_Redis extends Zend_Application_Resource_ResourceAbstract {

    protected $_config;

    public function init() {

//        return false;
     	$options = $this->getOptions();


     	$frontendOptions = array(
		    'cache_id_prefix' => $options['namespace'],
		    'automatic_serialization' => true
		);

		$backendOptions = array(
		    'servers' => array(
		        array('host' => $options['servers'][0]['host'], 'port' => $options['servers'][0]['port'])
		    )
		);

		$cache = \Zend_Cache::factory(
		    'Core',
		    'Rediska_Zend_Cache_Backend_Redis',
		    $frontendOptions,
		    $backendOptions,
		    false,
		    true
		);

        //set session to redis
        $options = array(
            'keyPrefix' => 'SESSIONS_Automoto',
            'lifetime'  => 3600,
            'rediska'   => array(
                 'servers' => array(
                      array('host' => $options['servers'][0]['host'], 'port' => $options['servers'][0]['port'])
                 )
            )
        );

        $saveHandler = new Rediska_Zend_Session_SaveHandler_Redis($options);

        \Zend_Session::setSaveHandler($saveHandler);
        \Zend_Session::start();
     	return $cache;
    }

}
